package cn.itcast.itcaststore.web.servlet.manager;

import cn.itcast.itcaststore.domain.Orders;
import cn.itcast.itcaststore.serive.OrderService;
import cn.itcast.itcaststore.serive.impl.OrderServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 根据订单id和收件人搜索订单
 */
@WebServlet("/admin/findOrderByManyCondition")
public class FindOrderByManyConditionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //1.获取订单编号和收件人姓名
        String orderId = req.getParameter("orderId");
        String receiverName = req.getParameter("receiverName");
        System.out.println(orderId);
        System.out.println(receiverName);
        //2.创建service层对象
        OrderService orderService = new OrderServiceImpl();
        //3.调用service层查询订单列表方法
       List<Orders> ordersList = orderService.findOrderByManyCondition(orderId,receiverName);
       //4.将查询结果添加到request作用域
        req.setAttribute("orders",ordersList);
        //5.请求转发到list.jsp页面
        req.getRequestDispatcher("/admin/orders/list.jsp").forward(req,resp);
    }
}
